package com.ruoyi.web.controller.hotel;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hotel.domain.DishOrderDetail;
import com.ruoyi.hotel.service.IDishOrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Controller
 * 
 * @author chen
 * @date 2022-05-03
 */
@RestController
@RequestMapping("/hotel/detail")
public class DishOrderDetailController extends BaseController
{
    @Autowired
    private IDishOrderDetailService dishOrderDetailService;

    /**
     * 查询列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DishOrderDetail dishOrderDetail)
    {
        List<DishOrderDetail> list = dishOrderDetailService.selectDishOrderDetailList(dishOrderDetail);
        return getDataTable(list);
    }

    /**
     * 导出列表
     */
    @Log(title = "", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DishOrderDetail dishOrderDetail)
    {
        List<DishOrderDetail> list = dishOrderDetailService.selectDishOrderDetailList(dishOrderDetail);
        ExcelUtil<DishOrderDetail> util = new ExcelUtil<DishOrderDetail>(DishOrderDetail.class);
        util.exportExcel(response, list, "数据");
    }

    /**
     * 获取详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dishOrderDetailService.selectDishOrderDetailById(id));
    }

    /**
     * 新增
     */
    @Log(title = "", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DishOrderDetail dishOrderDetail)
    {
        return toAjax(dishOrderDetailService.insertDishOrderDetail(dishOrderDetail));
    }

    /**
     * 修改
     */
    @Log(title = "", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DishOrderDetail dishOrderDetail)
    {
        return toAjax(dishOrderDetailService.updateDishOrderDetail(dishOrderDetail));
    }

    /**
     * 删除
     */
    @Log(title = "", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dishOrderDetailService.deleteDishOrderDetailByIds(ids));
    }
}
